package utils

import (
	"fmt"
	"sync"
)

type Container struct {
	list *ListItem
	lock sync.RWMutex
}

func NewContainer() *Container {
	return &Container{}
}

func (a *Container) Add(item interface{}) error {
	a.lock.Lock()
	defer a.lock.Unlock()

	if item == nil {
		return fmt.Errorf("param is nil")
	}

	if a.list == nil {
		a.list = NewListItem(item)
	} else {
		a.list = a.list.Push(NewListItem(item))
	}
	return nil
}
